package com.lw.Pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author LW
 * @2020/8/18 23:30
 */
//测试线程池
public class TestPool {

    public static void main(String[] args) {

        //创建线程池，大小为10
        ExecutorService service = Executors.newFixedThreadPool(10);
        //执行    线程池的大小在同时创建的线程
        service.execute(new MyThread());
        service.execute(new MyThread());
        service.execute(new MyThread());//submit方法有返回值，一般用来执行callable有返回值,
        service.execute(new MyThread());//execute是没有返回值的，一般用来执行Runnable
        service.execute(new MyThread());
        service.execute(new MyThread());
        service.execute(new MyThread());
        service.execute(new MyThread());
        service.execute(new MyThread());
        service.execute(new MyThread());
        //关闭连接
        service.shutdown();
    }
}

class MyThread implements Runnable{

    @Override
    public void run() {
            System.out.println(Thread.currentThread().getName());
    }
}